<html>
<head><meta charset="utf-8"><title>Getting unexpected publish diagnostics notifications · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Getting.20unexpected.20publish.20diagnostics.20notifications.html">Getting unexpected publish diagnostics notifications</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="218129295"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Getting%20unexpected%20publish%20diagnostics%20notifications/near/218129295" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Martin Asquino <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Getting.20unexpected.20publish.20diagnostics.20notifications.html#218129295">(Nov 27 2020 at 21:09)</a>:</h4>
<p>Hello again! I noticed something in my workflow that I'm not sure if it's a client issue or server issue, but for one it seems like it doesn't happen with for example the Go language server.</p>
<p>The issue I'm seeing is something like this: if I enter insert mode in vim and say I add 10 lines all of which have a diagnostic to be reported, then I leave insert mode, everything is fine at this point. When I save that file though, and the client sends the did_save notification, the server eventually ends up sending 10 publish diagnostics notifications to the client, and it seems like they are incrementally reporting the diagnostics. So for example, the first  notification has one the first diagnostic, the second notification has the first two diagnostics, the third notification has the first three, etc. Is this a known issue? Or is this some sort of incremental approach that is expected?</p>



<a name="218129590"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Getting%20unexpected%20publish%20diagnostics%20notifications/near/218129590" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Getting.20unexpected.20publish.20diagnostics.20notifications.html#218129590">(Nov 27 2020 at 21:14)</a>:</h4>
<p>Yeah, this does look like the expected behavior from looking at the code</p>



<a name="218129598"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Getting%20unexpected%20publish%20diagnostics%20notifications/near/218129598" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Getting.20unexpected.20publish.20diagnostics.20notifications.html#218129598">(Nov 27 2020 at 21:14)</a>:</h4>
<p>Does it cause problems? Aside from being inefficient, of course</p>



<a name="218130021"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Getting%20unexpected%20publish%20diagnostics%20notifications/near/218130021" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Martin Asquino <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Getting.20unexpected.20publish.20diagnostics.20notifications.html#218130021">(Nov 27 2020 at 21:21)</a>:</h4>
<p>Not really causing issues no, I was just confused about it. I don't suppose you know why that is the case, but now I'm curious and I have to ask <span aria-label="grinning" class="emoji emoji-1f600" role="img" title="grinning">:grinning:</span></p>



<a name="218130220"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Getting%20unexpected%20publish%20diagnostics%20notifications/near/218130220" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Getting.20unexpected.20publish.20diagnostics.20notifications.html#218130220">(Nov 27 2020 at 21:24)</a>:</h4>
<p>Each rustc diagnostics is received as a <code>flycheck::Message::AddDiagnostic</code> <a href="https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/rust-analyzer/src/main_loop.rs#L293">here</a>. A <a href="https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/rust-analyzer/src/main_loop.rs#L360">bit later</a> we check for file whose diagnostics changed, and send all diagnostics of that file to the client.</p>
<p>Since both happens once per loop turn we'll resend all diagnostics of a file for every new rustc diagnostic.</p>



<a name="218130365"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Getting%20unexpected%20publish%20diagnostics%20notifications/near/218130365" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Getting.20unexpected.20publish.20diagnostics.20notifications.html#218130365">(Nov 27 2020 at 21:27)</a>:</h4>
<p>The fix is to do the same thing we already do for VFS and PrimeCaches: Coalesce as many messages as possible from the flycheck receiver into a single loop turn.</p>



<a name="218130484"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Getting%20unexpected%20publish%20diagnostics%20notifications/near/218130484" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Martin Asquino <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Getting.20unexpected.20publish.20diagnostics.20notifications.html#218130484">(Nov 27 2020 at 21:29)</a>:</h4>
<p>oh ok so this is something that would be ideally fixed then, it's not a design decision that's set in stone</p>



<a name="218131696"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Getting%20unexpected%20publish%20diagnostics%20notifications/near/218131696" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Getting.20unexpected.20publish.20diagnostics.20notifications.html#218131696">(Nov 27 2020 at 21:53)</a>:</h4>
<p><span class="user-mention" data-user-id="246514">@Martin Asquino</span> <a href="https://github.com/rust-analyzer/rust-analyzer/pull/6656">https://github.com/rust-analyzer/rust-analyzer/pull/6656</a> should fix the issue, could you try that?</p>



<a name="218131820"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Getting%20unexpected%20publish%20diagnostics%20notifications/near/218131820" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Martin Asquino <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Getting.20unexpected.20publish.20diagnostics.20notifications.html#218131820">(Nov 27 2020 at 21:55)</a>:</h4>
<p>hm I pretty much made the same modification in my local copy of ra and it didn't seem to fix, but I'll try yours just in case</p>



<a name="218131876"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Getting%20unexpected%20publish%20diagnostics%20notifications/near/218131876" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Martin Asquino <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Getting.20unexpected.20publish.20diagnostics.20notifications.html#218131876">(Nov 27 2020 at 21:56)</a>:</h4>
<p>but I reckon that's the best we can do in any case</p>



<a name="218131922"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Getting%20unexpected%20publish%20diagnostics%20notifications/near/218131922" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Getting.20unexpected.20publish.20diagnostics.20notifications.html#218131922">(Nov 27 2020 at 21:57)</a>:</h4>
<p>If diagnostics are coming in too slowly from rustc, it might not have an effect</p>



<a name="218131999"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Getting%20unexpected%20publish%20diagnostics%20notifications/near/218131999" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Getting.20unexpected.20publish.20diagnostics.20notifications.html#218131999">(Nov 27 2020 at 21:58)</a>:</h4>
<p>For example, the PrimeCaches coalescing code still results in a few dozen messages, even though they arrive so quickly that I never see the progress indicator show up</p>



<a name="218132026"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Getting%20unexpected%20publish%20diagnostics%20notifications/near/218132026" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Getting.20unexpected.20publish.20diagnostics.20notifications.html#218132026">(Nov 27 2020 at 21:58)</a>:</h4>
<p>Maybe what we need is to actually delay for a couple milliseconds before sending these sorts of incremental updates to the client</p>



<a name="218167491"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Getting%20unexpected%20publish%20diagnostics%20notifications/near/218167491" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Getting.20unexpected.20publish.20diagnostics.20notifications.html#218167491">(Nov 28 2020 at 14:56)</a>:</h4>
<blockquote>
<p>Maybe what we need is to actually delay for a couple milliseconds before sending these sorts of incremental updates to the client</p>
</blockquote>
<p>Yeah, this seems like a good idea.</p>



<a name="218167504"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Getting%20unexpected%20publish%20diagnostics%20notifications/near/218167504" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Getting.20unexpected.20publish.20diagnostics.20notifications.html#218167504">(Nov 28 2020 at 14:56)</a>:</h4>
<p>The problem here though, is that I don't know how ti implement this logic in a simple and composable way.</p>



<a name="218167604"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Getting%20unexpected%20publish%20diagnostics%20notifications/near/218167604" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Getting.20unexpected.20publish.20diagnostics.20notifications.html#218167604">(Nov 28 2020 at 14:59)</a>:</h4>
<p>The ideal debouncing behavior is this:</p>
<ul>
<li>when the first event comes, emit it immediatelly.</li>
<li>then, emit the next event not sooner than after <em>delay</em> ms</li>
<li>if there's no new events and there's a delayed event, emit it after <em>delay</em> ms</li>
</ul>



<a name="218167610"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Getting%20unexpected%20publish%20diagnostics%20notifications/near/218167610" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Getting.20unexpected.20publish.20diagnostics.20notifications.html#218167610">(Nov 28 2020 at 14:59)</a>:</h4>
<p>And the last bit requries support for timers</p>



<a name="218167806"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Getting%20unexpected%20publish%20diagnostics%20notifications/near/218167806" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Getting.20unexpected.20publish.20diagnostics.20notifications.html#218167806">(Nov 28 2020 at 15:03)</a>:</h4>
<p>it almost feels like we should make the <code>main_loop</code> async <span aria-label="fear" class="emoji emoji-1f628" role="img" title="fear">:fear:</span></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>